package com.schoolcloud.social.controller.event;

import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.model.R;
import com.schoolcloud.common.util.UserContext;
import com.schoolcloud.social.entity.SocEventRemark;
import com.schoolcloud.social.query.EventRemarkQuery;
import com.schoolcloud.social.service.EventInteractionService;
import com.schoolcloud.social.service.SocEventRemarkService;
import com.schoolcloud.social.vo.EventReplyVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/social/event/remark")
@RequiredArgsConstructor
public class SocEventRemarkController {
    private final SocEventRemarkService socEventRemarkService;
    private final EventInteractionService eventInteractionService;
    @GetMapping("/page")
    public R<PageDTO<EventReplyVO>> getEventRemarkPageByEventId(EventRemarkQuery query) {
        PageDTO<EventReplyVO> page=eventInteractionService.getEventRemarkPage(query);
        return R.ok(page);
    }
    @PostMapping
    public R addEventRemark(@RequestBody SocEventRemark remark) {
        remark.setUserId(UserContext.getUserToInteger());
        remark.setCreateTime(LocalDateTime.now());
        socEventRemarkService.save(remark);
        return R.ok();
    }
    @DeleteMapping("/{id}")
    public R deleteEventRemark(@PathVariable Integer id) {
        socEventRemarkService.removeById(id);
        return R.ok();
    }
    @PostMapping("/reply")
    public R replyEventRemark(@RequestBody SocEventRemark remark) {
        remark.setUserId(UserContext.getUserToInteger());
        socEventRemarkService.save(remark);
        return R.ok();
    }
}
